<?php
/**
 *权限调用类
 *@author sulwan@126.com
 *@date 2009-11-20
 */

 class Work extends Application{

 public function __construct() {
    parent::__construct();
 }

/**
 *获取工作流列表
 */
public function getWork($page,$num,$findkey='',$order='id',$fields='*') {
	$numrows = intval($num);
	$page = (intval($page) > 0) ? intval($page) : 1;
	$offset = ($page -1) * $numrows;
	#
	$where = is_array($findkey) ? implode(' AND ', $findkey) : $findkey;
	$where = empty ($where) ? '' : ' WHERE ' . $where;
	#
	$orderby = ($orderby == '+') ? 'ASC' : 'DESC';
	$order = empty ($order) ? '' : (' ORDER BY ' . $order . ' ' . $orderby);
	#
	$limits =  '  LIMIT '.$offset.','.$numrows;
	#
	$sql = 'SELECT '. $fields . ' FROM ' . '#happy_workflow';
	$sql .= $where . $order . $limits;
	#
	$rs = $this->_db->getAll($sql);
	return $rs;
}


/**
 *统计工作流数量
 */
public function getWorkCount($findkey='') {
	$where = is_array($findkey) ? implode(' AND ', $findkey) : $findkey;
	$where = empty ($where) ? '' : ' WHERE ' . $where;
	$sql = 'SELECT count(*) FROM #happy_workflow';
	$sql .= $where;
	return $this->_db->getOne($sql);
}

/**
 *添加工作流
 */
public function addWork($data) {
	$data = array_map('mysql_escape',$data);
	$sql = "INSERT INTO `#happy_workflow`(`".implode("`,`",array_keys($data))."`)VALUES('".implode("','",array_values($data))."')";
	$id = $this->_db->execute($sql);
	return $id;
}

/**
 *添加工作流环节
 */
public function workflowAdd($data) {
	$data = array_map('mysql_escape',$data);
	$sql = "INSERT INTO `#happy_workflow_list`(`".implode("`,`",array_keys($data))."`)VALUES('".implode("','",array_values($data))."')";
	$id = $this->_db->execute($sql);
	return $id;
}

/**
 *获取工作流步骤列表
 */
public function getWorkList($page,$num,$findkey='',$order='id',$fields='*') {
	$numrows = intval($num);
	$page = (intval($page) > 0) ? intval($page) : 1;
	$offset = ($page -1) * $numrows;
	#
	$where = is_array($findkey) ? implode(' AND ', $findkey) : $findkey;
	$where = empty ($where) ? '' : ' WHERE ' . $where;
	#
	$orderby = ($orderby == '+') ? 'ASC' : 'DESC';
	$order = empty ($order) ? '' : (' ORDER BY ' . $order . ' ' . $orderby);
	#
	$limits =  '  LIMIT '.$offset.','.$numrows;
	#
	$sql = 'SELECT '. $fields . ' FROM ' . '#happy_workflow_list';
	$sql .= $where . $order . $limits;
	#
	$rs = $this->_db->getAll($sql);
	return $rs;
}


/**
 *统计工作流步骤数量
 */
public function getWorkListCount($findkey='') {
	$where = is_array($findkey) ? implode(' AND ', $findkey) : $findkey;
	$where = empty ($where) ? '' : ' WHERE ' . $where;
	$sql = 'SELECT count(*) FROM #happy_workflow_list';
	$sql .= $where;
	return $this->_db->getOne($sql);
}

}
 ?>